<?php

/**
 * This is the model class for table "game".
 *
 * The followings are the available columns in table 'game':
 * @property integer $id
 * @property string $game
 * @property string $tag
 * @property string $faction
 *
 * The followings are the available model relations:
 * @property Character[] $characters
 * @property Class[] $classes
 * @property Guild[] $guilds
 * @property Instances[] $instances
 * @property Pointtriggers[] $pointtriggers
 * @property Race[] $races
 * @property Rank[] $ranks
 * @property Recruitment[] $recruitments
 */
class Game extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Game the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'game';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('game, faction', 'length', 'max'=>45),
			array('tag', 'length', 'max'=>5),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, game, tag, faction', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'characters' => array(self::HAS_MANY, 'Character', 'gameId'),
			'classes' => array(self::HAS_MANY, 'Class', 'gameId'),
			'guilds' => array(self::HAS_MANY, 'Guild', 'gameId'),
			'instances' => array(self::HAS_MANY, 'Instances', 'gameId'),
			'pointtriggers' => array(self::HAS_MANY, 'Pointtriggers', 'gameId'),
			'races' => array(self::HAS_MANY, 'Race', 'gameId'),
			'ranks' => array(self::HAS_MANY, 'Rank', 'gameId'),
			'recruitments' => array(self::HAS_MANY, 'Recruitment', 'gameId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'game' => 'Game',
			'tag' => 'Tag',
			'faction' => 'Faction',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('game',$this->game,true);
		$criteria->compare('tag',$this->tag,true);
		$criteria->compare('faction',$this->faction,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}